package com.example.mark.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mark.entity.College;
import com.example.mark.entity.CollegeMark;
import com.example.mark.entity.CollegeSort;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.*;

import java.math.BigInteger;
import java.util.List;

@Mapper
public interface CollegeMapper extends BaseMapper<College> {
    @Select("SELECT c.*,cm.comprehensive_score " +
            "FROM college c " +
            "JOIN comprehensive_mark cm ON cm.college_id = c.college_id " +
            "ORDER BY cm.comprehensive_score DESC " +
            "LIMIT #{limit} OFFSET #{offset}")
    @Results({
            @Result(property = "collegeId", column = "college_id"),
            @Result(property = "campusName", column = "campus_name"),
            @Result(property = "photoPath", column = "photo_path"),
            @Result(property = "campusInformation", column = "campus_information"),
            @Result(property = "position", column = "position"),
            @Result(property = "tag", column = "tag"),
            @Result(property = "comprehensiveScore", column = "comprehensive_score")
    })
    List<CollegeMark> selectComprehensiveMarkWithCollege(@Param("limit") int limit, @Param("offset") int offset);

    @Select("SELECT c.*, cm.comprehensive_score " +
            "FROM college c " +
            "JOIN comprehensive_mark cm ON cm.college_id = c.college_id " +
            "WHERE c.campus_name LIKE CONCAT('%', #{collegeName}, '%')" +
            "ORDER BY cm.comprehensive_score DESC " +
            "LIMIT #{limit} OFFSET #{offset}")
    @Results({
            @Result(property = "collegeId", column = "college_id"),
            @Result(property = "campusName", column = "campus_name"),
            @Result(property = "photoPath", column = "photo_path"),
            @Result(property = "campusInformation", column = "campus_information"),
            @Result(property = "position", column = "position"),
            @Result(property = "tag", column = "tag"),
            @Result(property = "comprehensiveScore", column = "comprehensive_score")
    })
    List<CollegeMark> selectComprehensiveMarkWithCollegeLike(@Param("limit") int limit, @Param("offset") int offset ,@Param("collegeName") String collegeName);

    @Select("SELECT cs.* " +
            "FROM college_sort cs " +
            "WHERE cs.college_id = #{collegeId} " +
            "AND cs.sort = #{sort} " +
            "ORDER BY cs.endorse DESC")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "collegeId", column = "college_id"),
            @Result(property = "sort", column = "sort"),
            @Result(property = "photoPath", column = "photo_path"),
            @Result(property = "content", column = "content"),
            @Result(property = "endorse", column = "endorse")
    })
    List<CollegeSort> selectCollegeSortByCollegeIdAndSort(@Param("collegeId") BigInteger collegeId, @Param("sort") int sort);

}

